package com.example.siyun.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;

/**
 * @Auther: 全
 * @Date: 2022/10/12 09:21
 * @Description:自定义MD5加密的工具类
 */
@Slf4j
public class MD5Util {
    public static String encode(String password) {
        String saltsalt = (String) WebUtils.getSession().getAttribute("saltsalt");
        String md5Password = getMD5Password(password, saltsalt);
        log.info("获取自定义加密密码成功"+md5Password);
        return md5Password;
    }
    private static String getMD5Password(String password, String salt){
        log.info("密码"+password+"盐值"+salt);
        for (int i=0;i<3;i++){
            password= DigestUtils.md5DigestAsHex((salt+password+salt).getBytes()).toUpperCase();
        }
        log.info("返回加密密码成功");
        return password;
    }
}
